<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.10.0/jquery.js"></script>
    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
    <script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>

    <!-- Bootstrap CSS -->
<!--    <link rel="stylesheet" href="/css/bootstrap.css">-->
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.2/css/bootstrap.css" rel="stylesheet">
    <script>
        var id;
        var sec ;
        $(function() {
            var orderId = $.cookie("orderId");
            $.ajax({
                url: "http://localhost:8080/order/"+orderId,
                type: "GET",
                success:function (data) {
                    id = data.id;
                    sec = (data.createTime+data.expiration-Date.parse(new Date()))/1000;
                    $("#orderNo").html("订单："+data.orderNo);//createTime

                    time(sec)

                }
            })

            $("#submitBtn").on("click",function () {
                $.ajax({
                    url: "http://localhost:8080/order/pay/"+orderId,
                    type: "POST",
                    success:function (data) {
                        if(data ){
                            location.href = "success.html";
                        }else{
                            location.href = "list.html";
                        }
                    }
                    //dataType: "text"
                })
            })

        })

        function time(o) {
            if(o>0){
                $("#time").html(o+"秒后未支付订单取消");
                sec = sec-1;
                setTimeout(function() {
                        time(sec)
                    },
                    1000)

            }

        }

    </script>
    <title>Hello, world!</title>

</head>
<body>
<br class="container">
    <div id="orderNo"></div>
    </br>
    <div id="time"></div>
    </br>
    <button type="button" id="submitBtn" class="btn btn-primary">支付</button>

</body>
</html>
